﻿namespace CursorLearnForCSharp
{
    internal class Program
    {
        static void Main(string[] args)
        {

            Console.WriteLine("---------------Strategy Pattern-----------------");
            var calculator = new Calculator();
            var operation = calculator.GetOperation("+");
            var result = calculator.Calculate(1, 2, operation);
            Console.WriteLine(result);
            
            Console.WriteLine("\n\n\n");
            Console.WriteLine("---------------Decorator Pattern-----------------");
            var person = new Person { Name = "John" };
            var jk = new JK(person);
            var silk = new Silk(jk);
            jk.Show();
            Console.WriteLine("--------------------------------");
            silk.Show();

            Console.WriteLine("\n\n\n");
            Console.WriteLine("---------------Proxy Pattern-----------------");
            var receiver = new Receiver("John");
            var proxy = new Proxy(receiver);
            proxy.SendString("Hello");
            proxy.SendFile("file.txt");
            proxy.SendImage("image.jpg");

            Console.WriteLine("\n\n\n");
            Console.WriteLine("---------------Factory Method Pattern-----------------");
            var addFactory = new AddFactory();
            var addOperation = addFactory.CreateOperation();
            var addResult = calculator.Calculate(1, 2, addOperation);
            Console.WriteLine(addResult);

            Console.WriteLine("\n\n\n");
            Console.WriteLine("---------------State Pattern-----------------");
            var context = new Context();
            context.ChangeState(new Idle());
            
            // 模拟状态转换
            Console.WriteLine("初始状态：");
            context.Handle();
            
            Console.WriteLine("\n条件=1，切换到行走状态：");
            context.condition = 1;
            context.Handle();
            
            Console.WriteLine("\n条件=2，切换到跑步状态：");
            context.condition = 2;
            context.Handle();
            
            Console.WriteLine("\n条件=3，切换回空闲状态：");
            context.condition = 3;
            context.Handle();
            
        }
    }
}
